define( [
  'require',
  'jquery',
  'transit',
  'styleFilter',
  '../../lib/components',
  'api'
], function( require, $ ) {
  var style = require( 'styleFilter' );
  var components = require( '../../lib/components' );

  var api = require( 'api' ).EDIT_TEXT;
  var exportParam = $.extend( true, {}, style );
  var initBackup = exportParam.init;
  //var style = require( 'styleFilter' );
  var self = $( '.content-list .festival' );
  delete exportParam.options.class;
  exportParam.options.festival = $( '.js_all_festival [data-festival]', self ).map( function() {
    return $( this ).data( 'festival' );
  } ).get().join( ',' );

  exportParam.init = function() {

    if ( !this.inited ) {
      this.inited = true;
      initBackup.call( exportParam, null, {
        container: '.festival-style-content .dynamic-style',
        scroll: '.festival-style-content .style-material-container',
        filter: '#top-nav-festival .filter'
      }, true );
      $( '.festival_nav>li', self ).eq( 0 ).find( '>.filter' ).trigger( 'click' );
    }

  }

  function setLine( obj ) {
    $( '.festival_nav .active-line', self ).transit( obj );
  }

  self.on( 'click', 'a.filter,a.filter-static-style', function() {
    var $parent = $( this ).parents( '.festival-nav-item' );
    setLine( {
      x: $parent.position().left,
      width: $parent.outerWidth()
    } );
    $( '.festival-style-content>*', self ).eq( 0 ).removeClass( 'hide' ).siblings().addClass( 'hide' );

    if ( $( this ).hasClass( 'filter' ) ) {
      $( '.js_festival_text', self ).text( this.innerText );
    }
    if ( $( this ).hasClass( 'js_festival_text' ) ) {
      this.innerText = '所有节日';
    }
  } ).on( 'click', 'a.filter-images', function() {
    var $parent = $( this ).parents( '.festival-nav-item' );
    setLine( {
      x: $parent.position().left,
      width: $parent.outerWidth()
    } );

    /**
     * [取出节日图片]
     * @param  {[type]} 
     * @return {[type]}       [description]
     */
    $.ajax( {
      url: api.GET_FESTIVAL_IMAGES,
      method: 'post',
      data: {
        festival: $( this ).data( 'festival' )
      },
      success: function( data ) {
        var tempData = typeof data === 'string' ? JSON.parse( data ) : data;
        if ( tempData.ret === 0 ) {
          $( '.images-material-container', self ).append(
            components.imgListComponents( ( tempData.data ? tempData.data : [] ).map( function( item ) {
              return {
                title: item.title,
                img_url: item.url
              }
            } ) )
          );
        }
      },
      complete: function() {
        $( '.images-material-container .spinner', self ).hide();
      }
    } );

    $( '.images-material-container .spinner', self ).show();
    $( '.images-material-container .img_item_wrap', self ).remove();
    // 图片筛选条件
    $( '.festival-style-content>*', self ).eq( 1 ).removeClass( 'hide' ).siblings().addClass( 'hide' );
  } ).on( 'click', 'a.filter-static-style', function() {
    $( '.festival-style-content>*', self ).eq( 2 ).removeClass( 'hide' ).siblings().addClass( 'hide' );
  } );

  $( '.festival_nav > li', self ).hover( function() {
    var $dropMenu = $( '>.festival-drop-menu', this ).addClass( 'show' );
    $dropMenu[ 0 ] && $dropMenu[ 0 ].clientWidth;
    $dropMenu.addClass( 'open' );
  }, function() {
    $( '>.festival-drop-menu', this ).removeClass( 'open show' );
  } );

  return exportParam;
} );